﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace DBUtil
{
    /// <summary>
    /// 批量删除项
    /// </summary>
    public class DeleteBatchItem
    {
        private DeleteBatchItem() { }
        /// <summary>
        /// 表名
        /// </summary>
        public string TableName { get; private set; }
        /// <summary>
        /// 删除时的Where子句，以 "and" 开头
        /// </summary>
        public string WhereSql { get; private set; }
        /// <summary>
        /// 用于生成where子句的字典
        /// </summary>
        public IDictionary<string, object> WhereDic { get; private set; }
        /// <summary>
        /// 是否直接使用用户指定的where子句
        /// </summary>
        internal bool UseRawSql { get; private set; }

        /// <summary>
        /// 创建删除项，使用指定的where子句和参数数组
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="whereSql">where子句，以 "and" 开头</param>
        /// <param name="parameters">参数数组</param>
        /// <returns></returns>
        public static DeleteBatchItem Create(string tableName, string whereSql, IDictionary<string, object> parameters = null)
        {
            return new DeleteBatchItem()
            {
                TableName = tableName,
                WhereSql = whereSql,
                WhereDic = parameters,
                UseRawSql = true
            };
        }

        /// <summary>
        /// 创建删除项，使用字典生成where子句
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="whereDic">用于生成where子句的字典</param>
        /// <returns></returns>
        public static DeleteBatchItem Create(string tableName, IDictionary<string, object> whereDic)
        {
            return new DeleteBatchItem()
            {
                TableName = tableName,
                WhereDic = whereDic,
                UseRawSql = false
            };
        }
    }
}
